<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | Bigotry <3162875@qq.com>                               |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\admin\controller;

/**
 * Banner控制器
 */
class Banner extends AdminBase
{
    
    /**
     * Banner列表
     */
    public function bannerList()
    {
        
        $where = $this->logicbanner->getWhere($this->param);
        
        $this->assign('list', $this->logicbanner->getbannerList($where, 'a.*,c.name as category_name', 'a.create_time desc'));
        
        return $this->fetch('banner_list');
    }
    
    /**
     * Banner添加
     */
    public function bannerAdd()
    {
        
        $this->bannerCommon();
        
        return $this->fetch('banner_edit');
    }
    
    /**
     * Banner编辑
     */
    public function bannerEdit()
    {
        
        $this->bannerCommon();
        
        $info = $this->logicbanner->getbannerInfo(['a.id' => $this->param['id']], 'a.*,c.name as category_name');

        
        $this->assign('info', $info);
        
        return $this->fetch('banner_edit');
    }
    
    /**
     * Banner添加与编辑通用方法
     */
    public function bannerCommon()
    {
        
        IS_POST && $this->jump($this->logicbanner->bannerEdit($this->param));
        
        $this->assign('banner_category_list', $this->logicbanner->getbannerCategoryList([], 'id,name', '', false));
    }
    
    /**
     * Banner分类添加
     */
    public function bannerCategoryAdd()
    {
        
        IS_POST && $this->jump($this->logicbanner->bannerCategoryEdit($this->param));
        
        return $this->fetch('banner_category_edit');
    }
    
    /**
     * Banner分类编辑
     */
    public function bannerCategoryEdit()
    {
        
        IS_POST && $this->jump($this->logicbanner->bannerCategoryEdit($this->param));
        
        $info = $this->logicbanner->getbannerCategoryInfo(['id' => $this->param['id']]);
        
        $this->assign('info', $info);
        
        return $this->fetch('banner_category_edit');
    }
    
    /**
     * Banner分类列表
     */
    public function bannerCategoryList()
    {
        
        $this->assign('list', $this->logicbanner->getbannerCategoryList());
       
        return $this->fetch('banner_category_list');
    }
    
    /**
     * Banner分类删除
     */
    public function bannerCategoryDel($id = 0)
    {
        
        $this->jump($this->logicbanner->bannerCategoryDel(['id' => $id]));
    }
    
    /**
     * 数据状态设置
     */
    public function setStatus()
    {
        
        $this->jump($this->logicAdminBase->setStatus('banner', $this->param));
    }
}
